2020-2021 Sunseeker Telemetry and Lighting System
comp_d_ex3_interruptVcompVs15V.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
33 // MSP430FR57xx Demo - COMPD interrupt capability; Vcompare is compared against
34 // internal 1.5V reference
35 //
36 // Description: Use CompD and internal reference to determine if input'Vcompare'
37 // is high of low. For the first time, when Vcompare exceeds the 1.5V internal
38 // reference, CDIFG is set and device enters the CompD ISR. In the ISR, CDIES is
39 // toggled such that when Vcompare is less than 1.5V internal reference;
40 // CDIFG is set.
41 // LED is toggled inside the CompD ISR
42 //
43 // MSP430FR5739
44 // ------------------
45 // /|\| |
46 // | | |
47 // --|RST P3.1/CD13|<--Vcompare
48 // | |
49 // | P3.4|----> 'high'(Vcompare>2.0V); 'low'(Vcompare<2.5V)
50 // | | |
51 // | | | LED 'ON'(Vcompare>2.0V); 'OFF'(Vcompare<2.5V)
52 // | |
53 //
54 //******************************************************************************
55 #include "driverlib.h"
56 
57 void main (void)
58 {
59  //Stop WDT
60  WDT_A_hold(WDT_A_BASE);
61 
62  //Set P3.4 as an output pin.
63  /*
64 
65  * Select Port 3
66  * Set Pin 4 as output
67  */
68  GPIO_setAsOutputPin(
69  GPIO_PORT_P3,
70  GPIO_PIN4
71  );
72  //Set P3.4 as Output Low.
73  /*
74 
75  * Select Port 3
76  * Set Pin 4 to output Low.
77  */
79  GPIO_PORT_P3,
80  GPIO_PIN4
81  );
82 
83  //Initialize the Comparator B module
84  /*
85  * Base Address of Comparator B,
86  * Pin CD13 to Positive(+) Terminal
87  * Reference Voltage to Negative(-) Terminal
88  * Normal Power Mode
89  * Output Filter On with minimal delay
90  * Non-Inverted Output Polarity
91  */
92  Comp_D_initParam param = {0};
93  param.positiveTerminalInput = COMP_D_INPUT13;
94  param.negativeTerminalInput = COMP_D_VREF;
95  param.outputFilterEnableAndDelayLevel = COMP_D_FILTEROUTPUT_OFF;
96  param.invertedOutputPolarity = COMP_D_NORMALOUTPUTPOLARITY;
97  Comp_D_init(COMP_D_BASE, &param);
98 
99  //Set the reference voltage that is being supplied to the (-) terminal
100  /*
101  * Base Address of Comparator D,
102  * Reference Voltage of 1.5 V,
103  * Lower Limit of 1.5*(32/32) = 1.5V,
104  * Upper Limit of 1.5*(32/32) = 1.5V,
105  * Static Mode Accuracy
106  */
107  Comp_D_setReferenceVoltage(COMP_D_BASE,
108  COMP_D_VREFBASE1_5V,
109  32,
110  32
111  );
112 
113  //Enable CompB Interrupt on default rising edge for CDIFG
114  Comp_D_setInterruptEdgeDirection(COMP_D_BASE, COMP_D_RISINGEDGE);
115 
116  // Clear any erroneous interrupts
117  Comp_D_clearInterrupt(COMP_D_BASE, (COMP_D_INTERRUPT_FLAG + COMP_D_INTERRUPT_FLAG_INVERTED_POLARITY));
118 
119  //Enable Interrupts
120  /*
121  * Base Address of Comparator B,
122  * Enable CompB Interrupt on default rising edge for CDIFG
123  */
124  Comp_D_clearInterrupt(COMP_D_BASE,
125  COMP_D_INTERRUPT
126  );
127 
128  Comp_D_enableInterrupt(COMP_D_BASE,
129  COMP_D_INTERRUPT
130  );
131 
132  //Allow power to Comparator module
133  Comp_D_enable(COMP_D_BASE);
134 
135  //Enter LPM4 with interrupts enabled
136  __bis_SR_register(LPM4_bits + GIE);
137 
138  //For debug
139  __no_operation();
140 }
141 
142 //******************************************************************************
143 //
144 //This is the COMP_B_VECTOR interrupt vector service routine.
145 //
146 //******************************************************************************
147 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
148 #pragma vector=COMP_D_VECTOR
149 __interrupt
150 #elif defined(__GNUC__)
151 __attribute__((interrupt(COMP_D_VECTOR)))
152 #endif
153 void COMP_D_D_ISR (void)
154 {
155  //Toggle the edge at which an interrupt is generated
156  Comp_D_toggleInterruptEdgeDirection(COMP_D_BASE);
157 
158  //Clear Interrupt flag
159  Comp_D_clearInterrupt(COMP_D_BASE, COMP_D_INTERRUPT_FLAG);
160 
161  //Toggle P3.4 output pin.
162  /*
163 
164  * Select Port 3
165  * Set Pin 4 as output
166  */
167  GPIO_toggleOutputOnPin(
168  GPIO_PORT_P3,
169  GPIO_PIN4
170  );
171 }
MPU_initThreeSegmentsParam param
void main(void)
void COMP_D_D_ISR(void)
__no_operation()
GPIO_setOutputLowOnPin(GPIO_PORT_LED1|GPIO_PORT_LED2, GPIO_PIN_LED1|GPIO_PIN_LED2)